﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FirmaTransportowa
{
    public class DispatcherPanelPresenter
    {
        private User user;
        private DispatcherPanelForm dispatcherPanelView;
        private DispatcherTransportsListForm dispatcherTransportsListView;
        private DispatcherPackagesListForm dispatcherPackagesListView;
        private DispatcherAddNewTransportForm dispatcherAddNewTransportView;

        public DispatcherPanelPresenter(User user)
        {
            this.user = user;
            this.dispatcherPanelView = new DispatcherPanelForm(this);
            this.showLoggedUserName();
            this.dispatcherPanelView.Show();
        }

        public void clean()
        {
            if (dispatcherTransportsListView != null) dispatcherTransportsListView.Dispose();
            if (dispatcherPackagesListView != null) dispatcherPackagesListView.Dispose();
            if (dispatcherAddNewTransportView != null) dispatcherAddNewTransportView.Dispose();
            if (dispatcherPanelView != null) dispatcherPanelView.Dispose();
        }

        public void showTransportsListView()
        {
            dispatcherTransportsListView = new DispatcherTransportsListForm(this);
            displayTransportsList();
            dispatcherTransportsListView.Show();
        }

        public void showPackagesListView()
        {
            dispatcherPackagesListView = new DispatcherPackagesListForm(this);
            displayPackagesList();
            dispatcherPackagesListView.Show();
        }

        public void showAddNewTransportView()
        {
            dispatcherAddNewTransportView = new DispatcherAddNewTransportForm(this, this.user);
            displayPackagesListForAddNewTransportView();
            dispatcherAddNewTransportView.Show();
        }

        private void displayTransportsList()
        {
            dispatcherTransportsListView.transportsGridView.DataSource = Transport.getTransportsListForDispatcher(user.id);
            dispatcherTransportsListView.showDataTable();
        }

        private void displayPackagesListForAddNewTransportView() 
        {
            dispatcherAddNewTransportView.packagesList.DataSource = Package.getPackagesForDispatcher(); 
        }

        private void displayPackagesList() {
            dispatcherPackagesListView.packagesGridView.DataSource = Package.getPackagesForDispatcher();
            dispatcherPackagesListView.showDataTable();
        }

        private void showLoggedUserName()
        {
            dispatcherPanelView.dispatcherName.Text = user.worker.name + " " + user.worker.surname;
        }

        public void refreshDriversList()
        { 
            
        }
    }
}
